<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>

    </div>
    <p></p>
    <script>
        var div = document.querySelector("div");


        function time() {
            var date = new Date();
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            var day = date.getDay();
            var h = date.getHours();
            var mi = date.getMinutes();
            var s = date.getSeconds();
            // console.log(`${y}年${m}月${d}日 星期${day} ${h}:${mi}:${s}`);
            div.innerHTML = `${y}年${m}月${d}日 星期${day} ${h}:${mi}:${s}`;
        }
        time()

        // 定时器 定时执行一段代码
        setInterval(time, 1000);


        var p = document.querySelector("p")
        function time2(){
            var date1 = new Date("2022-9-10").getTime();
            var date2 = new Date().getTime();
            var cha = date1 - date2;
            var y = parseInt(cha / 1000 / 60 / 60 / 24 / 30 / 12);
            var m = parseInt(cha / 1000 / 60 / 60 / 24 / 30 % 12);
            var d = parseInt(cha / 1000 / 60 / 60 / 24 % 30);
            var h = parseInt(cha / 1000 / 60 / 60 % 24);
            var mi = parseInt(cha / 1000 / 60 % 60);
            var s = parseInt(cha / 1000 % 60 );
            p.innerHTML = `距离中秋节还有 ${y}年${m}月${d}日 ${h}:${mi}:${s}`;
        // console.log(`${y}年${m}月${d}日 ${h}:${mi}:${s}`);
        }
        time2()
        setInterval(time2,1000)
        

    </script>
</body>

</html>